package org.example.service.user;

import org.testng.annotations.Test;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;

public class SQLServerConnectionTest {

    public static void main(String[] args) {
        String url = "jdbc:sqlserver://192.168.43.175:1433;databaseName=wscc";
        String username = "sa";
        String password = "0";

        try {
            // 加载SQL Server驱动程序
            Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");

            // 建立连接
            Connection conn = DriverManager.getConnection(url, username, password);
            if (conn != null) {
                System.out.println("连接成功！");
                conn.close(); // 关闭连接
            } else {
                System.out.println("连接失败！");
            }
        } catch (ClassNotFoundException e) {
            System.out.println("无法找到SQL Server驱动程序！");
            e.printStackTrace();
        } catch (SQLException e) {
            System.out.println("连接失败！请检查数据库配置和网络连接。");
            e.printStackTrace();
        }
    }

    @Test
    void testCode() {

    }
}
